/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogDetalleSolicitud.java
 * 
 * Created on 08-dic-2011, 13:26:11
 */

package edu.uoc.tds.pec4.aulas;

import edu.uoc.tds.pec4.rmi.GestorAulasInterface;
import edu.uoc.tds.pec4.beans.ReservaDTO;
import edu.uoc.tds.pec4.rmi.GestorDiccionarioInterface;
import edu.uoc.tds.pec4.common.util.Constantes;
import edu.uoc.tds.pec4.common.util.TDSLanguageUtils;
import edu.uoc.tds.pec4.common.util.UtilidadesGUI;
import edu.uoc.tds.pec4.server.bbdd.exceptions.GestorAulasException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import javax.swing.JButton;
import javax.swing.JOptionPane;

/**
 *
 * @author 3H2M
 */
public class DialogConsultaDetalleReserva extends javax.swing.JDialog {

    /** idSolicitud es el identificador de la solicitud en pantalla */
    private int idSolicitud;
    /** idReserva es el identificador de la reserva en pantalla */
    private int idReserva;
     /** res es el objeto DTO de la reserva */
    private ReservaDTO res;  

    /** objRemoto Es el objeto empleado como interfaz en la comunicación RMI */
    private GestorDiccionarioInterface objRemotoDic = null;
    private GestorAulasInterface objRemotoAula = null;


    /** Creates new form DialogDetalleSolicitud */
    public DialogConsultaDetalleReserva(java.awt.Frame parent, boolean modal,
                GestorDiccionarioInterface objRemotoDic, GestorAulasInterface objRemotoAula,
                int idReserva) {
        super(parent, TDSLanguageUtils.getMessage("aulas.detalle.reservas.titulo"), modal);

        this.idReserva = idReserva;
        this.objRemotoDic = objRemotoDic;
        this.objRemotoAula = objRemotoAula;

        initComponents();

        mostrarDatos();
        //Centramos la ventana en la pantalla
        UtilidadesGUI.centrarVentana(this,JOptionPane.getFrameForComponent(this));
    }
    private void setLabels() {
        DatosReserva.setBorder(javax.swing.BorderFactory.createTitledBorder(null, TDSLanguageUtils.getMessage("aulas.detalle.reservas.datosreserva"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
        jLabelIdReserva.setText(TDSLanguageUtils.getMessage("aulas.detalle.reservas.datosreserva.idreserva"));
        jLabelEstado.setText(TDSLanguageUtils.getMessage("aulas.detalle.reservas.datosreserva.estado"));
        jLabelEmpleado.setText(TDSLanguageUtils.getMessage("aulas.detalle.reservas.datosreserva.empleado"));
        jLabelIdAula.setText(TDSLanguageUtils.getMessage("aulas.detalle.reservas.datosreserva.idaula"));
        jLabelImporte.setText(TDSLanguageUtils.getMessage("aulas.detalle.reservas.datosreserva.importe"));
        
        cmdCerrar.setText(TDSLanguageUtils.getMessage("aulas.detalle.reservas.salir"));
    }

    /**
     * Muestra los datos de la reserva en pantalla
     */
    private void mostrarDatos() {
        try {

            // Deshabilitamos la edición de las cajas de texto
            txtIdReserva.setEditable(false);
            txtEstado.setEditable(false);
            txtEmpleado.setEditable(false);
            txtIdAula.setEditable(false);
            txtImporteReserva.setEditable(false);

            
            // Llamamos al objeto remoto
           
            res = objRemotoAula.getDetalleReserva(idReserva);
            //SolicitudDTO sol = objRemotoAula.g.getSolicitud(idSolicitud);

            // Cargamos los controles
            txtIdReserva.setText(res.getIdReserva().toString());
            txtEstado.setText(TDSLanguageUtils.getMessage("aulas.consulta.solicitudes.estado." + res.getEstado()));
            //txtEstado.setText(res.getEstado().toString());
            txtEmpleado.setText(res.getNomEmpleado());
            txtIdAula.setText(res.getIdAula().toString());
            txtImporteReserva.setText(res.getImporte().toString());
            
                      

        } catch (GestorAulasException giE) {
            JOptionPane.showMessageDialog(null,
                    TDSLanguageUtils.getMessage("aulas.consulta.reservas.err.gestor.desc") + Constantes.SL +
                    giE.getMessage(), TDSLanguageUtils.getMessage("aulas.consulta.reservas.err.gestor"),
                    JOptionPane.ERROR_MESSAGE);
        } catch (RemoteException eRe) {
            JOptionPane.showMessageDialog(null,
                    TDSLanguageUtils.getMessage("aulas.consulta.reservas.err.gestor.desc") + Constantes.SL +
                    eRe.getMessage(), TDSLanguageUtils.getMessage("aulas.consulta.reservas.err.remoto.desc"),
                    JOptionPane.ERROR_MESSAGE);
        }
    }
    
    /**
     * Este método inicializa el botón Cerrar
     *
     * @return javax.swing.JButton
     */
    private JButton getCmdCerrar() {
        if (cmdCerrar == null) {
            cmdCerrar = new JButton();
            cmdCerrar.setText(TDSLanguageUtils.getMessage("aulas.detalle.reservas.salir"));
            cmdCerrar.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    cmdCerrarActionPerformed(e);
                }
            });
        }
        return cmdCerrar;
    }

    /**
     * Método que maneja el evento sobre el botón de Cerrar.<br />
     * Realiza la operación de cierre del dialogo
     */
    private void cmdCerrarActionPerformed(ActionEvent e) {
        dispose();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        DatosReserva = new javax.swing.JPanel();
        jLabelIdReserva = new javax.swing.JLabel();
        txtIdReserva = new javax.swing.JTextField();
        jLabelEmpleado = new javax.swing.JLabel();
        txtEmpleado = new javax.swing.JTextField();
        jLabelEstado = new javax.swing.JLabel();
        txtEstado = new javax.swing.JTextField();
        jLabelIdAula = new javax.swing.JLabel();
        txtIdAula = new javax.swing.JTextField();
        txtImporteReserva = new javax.swing.JTextField();
        jLabelImporte = new javax.swing.JLabel();
        cmdCerrar = getCmdCerrar();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        DatosReserva.setBorder(javax.swing.BorderFactory.createTitledBorder(null, TDSLanguageUtils.getMessage("aulas.detalle.solicitudes.datossolicitud"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
        DatosReserva.setName(""); // NOI18N

        jLabelIdReserva.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabelIdReserva.setText("ID Reserva:");

        jLabelEmpleado.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabelEmpleado.setText("Empleado:");

        jLabelEstado.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabelEstado.setText("Estado:");

        jLabelIdAula.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabelIdAula.setText("ID Aula:");

        txtImporteReserva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtImporteReservaActionPerformed(evt);
            }
        });

        jLabelImporte.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabelImporte.setText("Importe:");

        javax.swing.GroupLayout DatosReservaLayout = new javax.swing.GroupLayout(DatosReserva);
        DatosReserva.setLayout(DatosReservaLayout);
        DatosReservaLayout.setHorizontalGroup(
            DatosReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DatosReservaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(DatosReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelIdReserva)
                    .addComponent(jLabelEstado)
                    .addComponent(jLabelEmpleado)
                    .addComponent(jLabelIdAula)
                    .addComponent(jLabelImporte))
                .addGap(18, 18, 18)
                .addGroup(DatosReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(DatosReservaLayout.createSequentialGroup()
                        .addComponent(txtImporteReserva, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(DatosReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(DatosReservaLayout.createSequentialGroup()
                            .addComponent(txtIdAula, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(DatosReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(DatosReservaLayout.createSequentialGroup()
                                .addComponent(txtEmpleado, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
                                .addContainerGap())
                            .addGroup(DatosReservaLayout.createSequentialGroup()
                                .addComponent(txtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(398, Short.MAX_VALUE))
                            .addGroup(DatosReservaLayout.createSequentialGroup()
                                .addComponent(txtIdReserva, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
                                .addGap(186, 186, 186))))))
        );
        DatosReservaLayout.setVerticalGroup(
            DatosReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DatosReservaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(DatosReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelIdReserva)
                    .addComponent(txtIdReserva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(DatosReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelEstado)
                    .addComponent(txtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(DatosReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelEmpleado)
                    .addComponent(txtEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(DatosReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelIdAula)
                    .addComponent(txtIdAula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(DatosReservaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelImporte)
                    .addComponent(txtImporteReserva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(32, Short.MAX_VALUE))
        );

        cmdCerrar.setText("Cerrar");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(DatosReserva, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(cmdCerrar)
                        .addGap(160, 160, 160))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(DatosReserva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addComponent(cmdCerrar)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtFechaIniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldFechaIniActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jTextFieldFechaIniActionPerformed

    private void txtHoraIniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldHoraIniActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldHoraIniActionPerformed
     /**
     * Método que maneja el evento sobre el botón de consultar aula.<br />
     * Realiza la operación de mostrar el diálogo de consultar aula
     */

    private void txtImporteReservaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtImporteReservaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtImporteReservaActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                DialogDetalleSolicitud dialog = new DialogDetalleSolicitud(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel DatosReserva;
    private javax.swing.JButton cmdCerrar;
    private javax.swing.JLabel jLabelEmpleado;
    private javax.swing.JLabel jLabelEstado;
    private javax.swing.JLabel jLabelIdAula;
    private javax.swing.JLabel jLabelIdReserva;
    private javax.swing.JLabel jLabelImporte;
    private javax.swing.JTextField txtEmpleado;
    private javax.swing.JTextField txtEstado;
    private javax.swing.JTextField txtIdAula;
    private javax.swing.JTextField txtIdReserva;
    private javax.swing.JTextField txtImporteReserva;
    // End of variables declaration//GEN-END:variables

}